import axios from 'axios'

const _axios = axios.create({
    baseURL: process.env.VUE_APP_URL
})

// 请求拦截
_axios.interceptors.request.use(config => { return config }, error => { return Promise.reject(error) })

// 响应拦截
_axios.interceptors.response.use(
    res => {
        return res.data
    },
    error => {
        return Promise.reject(error)
    }
)

// 发送请求方法
function ajax(url, method = 'get', params) {
    return _axios({
        url,
        method,
        [method.toLowerCase() === 'get' ? 'params' : 'data']: params
    })
}

export default _axios
